package com.gz.logistics.library.pojo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * author wanner1991
 */
public class ProductInfo implements Serializable {
    private String product_name;
    private double product_price;
    private int product_num;
    private int product_id;

    public int getProduct_id() {
        return product_id;
    }

    public void setProduct_id(int product_id) {
        this.product_id = product_id;
    }

    public String getProduct_name() {
        return product_name;
    }

    public void setProduct_name(String product_name) {
        this.product_name = product_name;
    }

    public double getProduct_price() {
        return product_price;
    }

    public void setProduct_price(double product_price) {
        this.product_price = product_price;
    }

    public int getProduct_num() {
        return product_num;
    }

    public void setProduct_num(int product_num) {
        this.product_num = product_num;
    }

    public static List<ProductInfo> parse(JSONArray jsonArray) throws JSONException {
        if (jsonArray == null || jsonArray.length() <= 0){
            return null;
        }
        List<ProductInfo> productInfoList = new ArrayList<ProductInfo>();
        for (int i = 0 ; i < jsonArray.length() ; i++ ){
            ProductInfo productInfo = new ProductInfo();
            JSONObject object = jsonArray.getJSONObject(i);
            productInfo.product_name = object.getString("product_name");
            productInfo.product_price = object.getDouble("product_price");
            productInfo.product_num = object.getInt("product_num");
            productInfo.product_id = object.getInt("product_id");
            productInfoList.add(productInfo);

        }
        return productInfoList;
    }
}
